using System;
using System.Collections;
using UnityEngine;

public class DebugRenderer : MonoBehaviour
{
	public string myLog;

	private Queue myLogQueue = new Queue();

	private void Start()
	{
		UnityEngine.Debug.Log("Debug Renderer enabled.");
	}

	private void OnEnable()
	{
		Application.logMessageReceived += HandleLog;
	}

	private void OnDisable()
	{
		Application.logMessageReceived -= HandleLog;
	}

	private void HandleLog(string logString, string stackTrace, LogType type)
	{
		myLog = logString;
		string obj = "\n [" + type + "] : " + myLog;
		myLogQueue.Enqueue(obj);
		if (type == LogType.Exception)
		{
			obj = "\n" + stackTrace;
			myLogQueue.Enqueue(obj);
		}
		myLog = string.Empty;
		IEnumerator enumerator = myLogQueue.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				string text = (string)enumerator.Current;
				myLog += text;
			}
		}
		finally
		{
			IDisposable disposable;
			if ((disposable = (enumerator as IDisposable)) != null)
			{
				disposable.Dispose();
			}
		}
		if (myLogQueue.Count > Screen.height / 25)
		{
			myLogQueue.Dequeue();
		}
	}

	private void OnGUI()
	{
		GUILayout.Label(myLog);
	}
}
